{include file="admin/header.htm"}
<form action="{$smarty.const.ADMIN_NAME}?m=admin&c=block&a=add_block" method="post" enctype="multipart/form-data">
    <table cellpadding="2" cellspacing="1" class="table_form">
        <caption>添加碎片</caption>
        <tr>
            <th><strong>碎片名称</strong></th>
            <td><input type="text" name="block_name" value="{$block.block_name}"></td>
        </tr>
        <tr>
            <th><strong>碎片内容</strong></th>
            <td id="wrap">
                {if empty($block) || empty($block.block_data)}
                <div style="margin:5px;padding:2px;background-color:#e7f5fe;color:blue;">
                    <p><span>排序</span><input type="text" name="orders[0]" value="0"></p>
                    {$index = 1}
                    {foreach $tpl.tpl_fields as $k => $v}
                      <p>
                          <span>{$v.name}</span>
                          <input id="{$k}" {if $v.type == 'file'}type="file"{else}type="text"{/if} name="data[0][{$k}]">
                          {if $v.type == 'date'}
                          <img onclick="WdatePicker({ldelim}el:'{$k}',lang:'en'{rdelim})" src="{geturl('/static/js/My97DatePicker/skin/datePicker.gif')}" width="16" height="22" align="absmiddle">
                          {/if}
                      </p>
                    {/foreach}
                    <a href="javascript:;" onclick="add()">添加</a> | <a href="javascript:;" onclick="del(this)">删除</a>
                </div>
                {else}
                {$index=0}
                {foreach $block.block_data as $kk => $vv}
                <div style="margin:5px;padding:2px;background-color:#e7f5fe;color:blue;">
                    <p><span>排序</span><input type="text" name="orders[{$index}]" value="{$index}"></p>
                    {foreach $tpl.tpl_fields as $k => $v}
                      <p>
                          <span>{$v.name}</span>
                          <input id="{$k}_{$index}" {if $v.type == 'file'}type="file"{else}type="text"{/if} name="data[{$index}][{$k}]" {if $v.type == 'date'}value="{date('Y-m-d', $vv[$k])}"{elseif $v.type == 'text'} value="{$vv[$k]}"{/if}>
                          {if $v.type == 'date'}
                          <img onclick="WdatePicker({ldelim}el:'{$k}_{$index}',lang:'en'{rdelim})" src="{geturl('/static/js/My97DatePicker/skin/datePicker.gif')}" width="16" height="22" align="absmiddle">
                          {/if}
                          {if $v.type == 'file' && !empty($vv[$k])}
                          <a href="{$smarty.const.BLOCK_URL}{$vv[$k]}" target="_blank"><img width="100" src="{$smarty.const.BLOCK_URL}{$vv[$k]}"></a>
                          {/if}
                      </p>
                    {/foreach}
                    <a href="javascript:;" onclick="add()">添加</a> | <a href="javascript:;" onclick="del(this)">删除</a>
                </div>
                {$index=$index+1}
                {/foreach}
                {/if}
            </td>
        </tr>
        <tr>
            <th></th>
            <td><input type="submit" name="doadd" value="添加" class="button_style"></td>
        </tr>
    </table>
    <input type="hidden" name="tpl_id" value="{$tpl.id}">
    <input type="hidden" name="id" value="{$block.id}">
</form>
{include file="admin/footer.htm"}
<script type="text/javascript" src="{geturl('/static/js/My97DatePicker/WdatePicker.js')}"></script>
<script type="text/javascript">
var index = {$index};
function add() {
    $('#wrap').append('<div style="margin:5px;padding:2px;background-color:#e7f5fe;color:blue;"><p><span>排序</span><input type="text" name="orders['+index+']" value="'+index+'"></p>{foreach $tpl.tpl_fields as $k => $v}<p><span>{$v.name}</span><input id="{$k}_'+index+'" {if $v.type == 'file'}type="file"{else}type="text"{/if} name="data['+index+'][{$k}]">{if $v.type == 'date'}<img onclick="WdatePicker({ldelim}el:\'{$k}_'+index+'\',lang:\'en\'{rdelim})" src="{geturl('/static/js/My97DatePicker/skin/datePicker.gif')}" width="16" height="22" align="absmiddle">{/if}</p>{/foreach}<a href="javascript:;" onclick="add()">添加</a> | <a href="javascript:;" onclick="del(this)">删除</a></div>');
    index++;
}

function del(obj) {
    $(obj).parent().remove();
}
</script>